local function clone(object)
    local lookup_table = {}
    local function _copy(object)
        if type(object) ~= 'table' then
            return object
        elseif lookup_table[object] then
            return lookup_table[object]
        end
        local newObject = {}
        lookup_table[object] = newObject
        for key, value in pairs(object) do
            newObject[_copy(key)] = _copy(value)
        end
        return setmetatable(newObject, getmetatable(object))
    end
    return _copy(object)
end

local RDB_MAP = {
    ALIYUN_WATERADMIN = {
        ctype = 'mysql',
        host = '39.100.149.120',
        user = 'root',
        password = 'aA.76366151',
        database = 'water_admin',
        charset = 'utf8'
    },
    ALIYUN_GAME_DEV = {
        ctype = 'mysql',
        host = '39.100.149.120',
        user = 'root',
        password = 'aA.76366151',
        database = 'game_dev'
    },
    XLTEST_CCPM = {
        ctype = 'mysql',
        host = '192.168.10.117',
        user = 'root',
        password = '123456',
        database = 'game_dev'
    },
    XLPRODUCT_CCPM = {
        ctype = 'mysql',
        host = '39.100.149.120',
        user = 'root',
        password = 'aA.76366151',
        database = 'game_dev'
    }
}

local RDS_MAP = {
    ALIYUN = {
        ctype = 'redis',
        host = '39.100.149.120',
        port = '6379',
        auth = 'aA.76366151'
    }
}

local CONFIG = {
    ['usr'] = {
        src = 'api.model.usr',
        dccfg = clone(RDB_MAP['ALIYUN_WATERADMIN']),
        def_db = 'auth_user'
    },
    ['actusr'] = {
        src = 'api.model.actusr',
        dccfg = clone(RDS_MAP['ALIYUN'])
    },
    ['ccpm'] = {
        src = 'api.model.ccpm',
        dccfg = clone(RDB_MAP['XLPRODUCT_CCPM']),
        def_db = 'ccpm_pack',
    },
    ['ccpmfav'] = {
        src = 'api.model.ranklist', 
        dccfg = clone(RDS_MAP['ALIYUN']),
        rankname = "ccpmfav"
    }
}

-- 转标忽略的key
local FAKE_KEYS = {
    src = true, 
    dccfg = true, 
    def_db = true
}

local function chk_extraparam(cdic, tdic)
    for k, v in pairs(cdic) do 
        if not FAKE_KEYS[k] then 
            tdic['dccfg'][k] = v
        end
    end
end

local function gen_ormmap()
    local dc
    local ret = clone(CONFIG)
    for i, v in pairs(CONFIG) do
        if v['def_db'] then
            ret[i]['dccfg']['tbname'] = v['def_db']
        end
        chk_extraparam(v, ret[i])
    end
    return ret
end
local c = gen_ormmap()

return c
